/**
 * Created with CLion.
 * Description: 
 * User: loong
 * Date: 2025/6/18
 * Time: 22:20
 */

#include "Spawner.h"

#include "Enemy.h"
#include "Player.h"
#include "core/Scene.h"
#include "world/Effect.h"

void Spawner::Update(float _dt)
{
    if(nullptr == target_ || !target_->IsActive())
        return;
    timer_ += _dt;

    if(timer_ >= interval_) {
        timer_ = 0;
        for(int i = 0; i < num_; i++) {
            // spawn enemy
            auto    pos   = game_.RandomVec2(game_.GetCurrentScene()->GetCameraPosition(), game_.GetCurrentScene()->GetCameraPosition() + game_.GetScreenSize());
            Enemy * enemy = Enemy::AddEnemyChild(nullptr, pos, target_);
            Effect::AddEffectChild(game_.GetCurrentScene(), "../assets/effect/184_3.png", pos, 1.0f, enemy);
        }
    }
}